﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;

namespace PLCWpfTest.Controls
{
    /// <summary>
    /// Title.xaml 的交互逻辑
    /// </summary>
    public partial class ModuleTitle : UserControl
    {
        private static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(ModuleTitle), new PropertyMetadata(string.Empty, null, CoerceValueCallback));

        [Bindable(true), Category("自定义属性"), Description("模块标题")]
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }

        public ModuleTitle()
        {
            InitializeComponent();
        }

        private static object CoerceValueCallback(DependencyObject d, object baseValue)
        {
            if (baseValue == null)
            {
                return baseValue;
            }
            string title = baseValue.ToString();
            ((ModuleTitle)d).TitleLabel.Content = title;
            return title;
        }
    }
}
